class Solution:
    def rotate(self, nums: List[int], k: int) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        n = len(nums)
        start = 0
        count = 0
        while count != n:
            curr_idx = start  # 从索引curr_idx开始，将它的值赋给索引(curr_idx + k) % n
            curr_val = nums[start]
            while True:
                next_idx = (curr_idx + k) % n
                temp = nums[next_idx]
                nums[next_idx] = curr_val
                curr_val = temp
                curr_idx = next_idx
                count += 1  # 整个数组只需要n次赋值就可以了，所以count==n
                if curr_idx == start:
                    start += 1  # 从start出发又回到了start，如果count小于n则从start+1处继续开始
                    break